// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

// Floating.ts
const { ccclass, property } = cc._decorator;
@ccclass
export default class Floating extends cc.Component {
    @property
    floatHeight: number = 35; // 浮动的高度
    @property
    duration: number = 1.8; // 动画持续时间
    start() {
        this.startFloating();
    }
    startFloating() {
        // 上升动作
        let moveUp = cc.moveBy(this.duration / 2, cc.v2(0, this.floatHeight)).easing(cc.easeCubicActionOut());
        // 下降动作
        let moveDown = cc.moveBy(this.duration / 2, cc.v2(0, -this.floatHeight)).easing(cc.easeCubicActionIn());
        // 创建无限循环动作
        let floating = cc.sequence(moveUp, moveDown).repeatForever();
        // 运行浮动动作
        this.node.runAction(floating);
    }
}


